<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="reduce我也是第一次听说数组还有一个reduce方法，要不是看别人的代码用到了这个，估计自己还不不会去查这样一个方法。reduce() 方法对累加器和数组中的每个元素（从左到右）应用一个函数，将其减少为单个值。最常见的代码：123var total = [0, 1, 2, 3].reduce(function(sum, value) &amp;#123;  return sum + value;&amp;#1">
<meta name="keywords" content="javascript">
<meta property="og:type" content="article">
<meta property="og:title" content="数组的不为人知的函数">
<meta property="og:url" content="https://andyliwr.github.io/2018/01/09/array_unknow_function/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="reduce我也是第一次听说数组还有一个reduce方法，要不是看别人的代码用到了这个，估计自己还不不会去查这样一个方法。reduce() 方法对累加器和数组中的每个元素（从左到右）应用一个函数，将其减少为单个值。最常见的代码：123var total = [0, 1, 2, 3].reduce(function(sum, value) &amp;#123;  return sum + value;&amp;#1">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-01-15T06:30:09.116Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="数组的不为人知的函数">
<meta name="twitter:description" content="reduce我也是第一次听说数组还有一个reduce方法，要不是看别人的代码用到了这个，估计自己还不不会去查这样一个方法。reduce() 方法对累加器和数组中的每个元素（从左到右）应用一个函数，将其减少为单个值。最常见的代码：123var total = [0, 1, 2, 3].reduce(function(sum, value) &amp;#123;  return sum + value;&amp;#1">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>数组的不为人知的函数</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2018/01/09/js_knn_algorithm/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2017/12/25/elememt_el_menu_bug/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/01/09/array_unknow_function/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&text=数组的不为人知的函数"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&is_video=false&description=数组的不为人知的函数"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=数组的不为人知的函数&body=Check out this article: https://andyliwr.github.io/2018/01/09/array_unknow_function/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&name=数组的不为人知的函数&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#reduce"><span class="toc-number">1.</span> <span class="toc-text">reduce</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#入参"><span class="toc-number">1.1.</span> <span class="toc-text">入参</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#描述"><span class="toc-number">1.2.</span> <span class="toc-text">描述</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#运行过程"><span class="toc-number">1.3.</span> <span class="toc-text">运行过程</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#常见用法"><span class="toc-number">1.4.</span> <span class="toc-text">常见用法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#兼容"><span class="toc-number">1.5.</span> <span class="toc-text">兼容</span></a></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        数组的不为人知的函数
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2018-01-09T14:24:23.000Z" itemprop="datePublished">2018-01-09</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/javascript/">javascript</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h4 id="reduce"><a href="#reduce" class="headerlink" title="reduce"></a>reduce</h4><p>我也是第一次听说数组还有一个reduce方法，要不是看别人的代码用到了这个，估计自己还不不会去查这样一个方法。<br><code>reduce()</code> 方法对累加器和数组中的每个元素（从左到右）应用一个函数，将其减少为单个值。最常见的代码：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> total = [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">sum, value</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> sum + value;</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br></pre></td></tr></table></figure></p>
<p>最后输出<code>total</code>为6</p>
<h5 id="入参"><a href="#入参" class="headerlink" title="入参"></a><strong>入参</strong></h5><ul>
<li><strong>callback</strong></li>
<li><strong>initialValue</strong><figure class="highlight golo"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">array</span>.<span class="keyword">reduce</span>(callback, initialValue)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>reduce的回调函数接受四个参数</p>
<ul>
<li><strong><code>accumulator</code></strong><br>累加器累加回调的返回值; 它是上一次调用回调时返回的累积值，或initialValue（如下所示）。</li>
<li><strong><code>currentValue</code></strong><br>数组中正在处理的元素。</li>
<li><strong><code>currentIndex</code></strong><br>数组中正在处理的当前元素的索引。 如果提供了initialValue，则索引号为0，否则为索引为1。</li>
<li><strong><code>array</code></strong><br>调用reduce的数组</li>
</ul>
<p><em>PS</em>：<code>initialValue</code>[可选] 用作第一个调用 <code>callback</code>的第一个参数的值。 如果没有提供初始值，则将使用数组中的第一个元素。 在没有初始值的空数组上调用 reduce 将报错</p>
<h5 id="描述"><a href="#描述" class="headerlink" title="描述"></a><strong>描述</strong></h5><p>回调函数第一次执行时，<code>accumulator</code> 和<code>currentValue</code>的取值有两种情况：调用<code>reduce</code>时提供<code>initialValue</code>，<code>accumulator</code>取值为<code>initialValue</code>，<code>currentValue</code>取数组中的第一个值；没有提供 <code>initialValue</code>，<code>accumulato</code>r取数组中的第一个值，<code>currentValue</code>取数组中的第二个值。<br>注意：如果没有提供<code>initialValue</code>，<code>reduce</code> 会从索引1的地方开始执行 <code>callback</code> 方法，跳过第一个索引。如果提供<code>initialValue</code>，从索引0开始。<br>如果数组为空且没有提供<code>initialValue</code>，会抛出<code>TypeError</code> 。如果数组仅有一个元素（无论位置如何）并且没有提供<code>initialValue</code>， 或者有提供<code>initialValue</code>但是数组为空，那么此唯一值将被返回并且<code>callback</code>不会被执行。</p>
<h5 id="运行过程"><a href="#运行过程" class="headerlink" title="运行过程"></a><strong>运行过程</strong></h5><p>运行下面的代码：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">accumulator, currentValue, currentIndex, array</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> accumulator + currentValue;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<p><code>callback</code> 被调用四次，每次调用的参数和返回值如下表:</p>
<table>
<thead>
<tr>
<th style="text-align:left">callback</th>
<th style="text-align:left">accumulator</th>
<th>currentValue</th>
<th style="text-align:left">currentIndex</th>
<th style="text-align:left">array</th>
<th style="text-align:left">return value</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">first call</td>
<td style="text-align:left">0</td>
<td>1</td>
<td style="text-align:left">1</td>
<td style="text-align:left">[0, 1, 2, 3, 4]</td>
<td style="text-align:left">1</td>
</tr>
<tr>
<td style="text-align:left">second call</td>
<td style="text-align:left">1</td>
<td>2</td>
<td style="text-align:left">2</td>
<td style="text-align:left">[0, 1, 2, 3, 4]</td>
<td style="text-align:left">3</td>
</tr>
<tr>
<td style="text-align:left">first call</td>
<td style="text-align:left">3</td>
<td>3</td>
<td style="text-align:left">3</td>
<td style="text-align:left">[0, 1, 2, 3, 4]</td>
<td style="text-align:left">6</td>
</tr>
<tr>
<td style="text-align:left">first call</td>
<td style="text-align:left">6</td>
<td>4</td>
<td style="text-align:left">4</td>
<td style="text-align:left">[0, 1, 2, 3, 4]</td>
<td style="text-align:left">10</td>
</tr>
</tbody>
</table>
<h5 id="常见用法"><a href="#常见用法" class="headerlink" title="常见用法"></a><strong>常见用法</strong></h5><ol>
<li><strong>数组累加</strong><br>见<strong>运行过程</strong>中的代码</li>
<li><p><strong>二维数组降维</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> flattened = [[<span class="number">0</span>, <span class="number">1</span>], [<span class="number">2</span>, <span class="number">3</span>], [<span class="number">4</span>, <span class="number">5</span>]].reduce(</span><br><span class="line">  <span class="function"><span class="keyword">function</span>(<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> a.concat(b);</span><br><span class="line">  &#125;,</span><br><span class="line">  []</span><br><span class="line">);</span><br><span class="line"><span class="comment">// flattened is [0, 1, 2, 3, 4, 5]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>计算数组中每个元素出现的次数</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> names = [<span class="string">'Alice'</span>, <span class="string">'Bob'</span>, <span class="string">'Tiff'</span>, <span class="string">'Bruce'</span>, <span class="string">'Alice'</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> countedNames = names.reduce(<span class="function"><span class="keyword">function</span> (<span class="params">allNames, name</span>) </span>&#123; </span><br><span class="line">  <span class="keyword">if</span> (name <span class="keyword">in</span> allNames) &#123;</span><br><span class="line">    allNames[name]++;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span> &#123;</span><br><span class="line">    allNames[name] = <span class="number">1</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> allNames;</span><br><span class="line">&#125;, &#123;&#125;);</span><br><span class="line"><span class="comment">// countedNames is:</span></span><br><span class="line"><span class="comment">// &#123; 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 &#125;</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="兼容"><a href="#兼容" class="headerlink" title="兼容"></a><strong>兼容</strong></h5><table>
<thead>
<tr>
<th style="text-align:left">Feature</th>
<th style="text-align:left">Chrome</th>
<th style="text-align:left">Edge</th>
<th style="text-align:left">Firefox</th>
<th style="text-align:left">Internet</th>
<th style="text-align:left">Explorer</th>
<th style="text-align:left">Opera</th>
<th style="text-align:left">Safari</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Basic</td>
<td style="text-align:left">support</td>
<td style="text-align:left">Yes</td>
<td style="text-align:left">Yes</td>
<td style="text-align:left">3</td>
<td style="text-align:left">9</td>
<td style="text-align:left">10.5</td>
<td style="text-align:left">4</td>
</tr>
</tbody>
</table>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#reduce"><span class="toc-number">1.</span> <span class="toc-text">reduce</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#入参"><span class="toc-number">1.1.</span> <span class="toc-text">入参</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#描述"><span class="toc-number">1.2.</span> <span class="toc-text">描述</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#运行过程"><span class="toc-number">1.3.</span> <span class="toc-text">运行过程</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#常见用法"><span class="toc-number">1.4.</span> <span class="toc-text">常见用法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#兼容"><span class="toc-number">1.5.</span> <span class="toc-text">兼容</span></a></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/01/09/array_unknow_function/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&text=数组的不为人知的函数"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&is_video=false&description=数组的不为人知的函数"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=数组的不为人知的函数&body=Check out this article: https://andyliwr.github.io/2018/01/09/array_unknow_function/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&title=数组的不为人知的函数"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/01/09/array_unknow_function/&name=数组的不为人知的函数&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


